package com.lcb.jmm.volatiledome;

/****
 * @Author:lcb
 * @Description:原子性
 * @Date: 2020-12-23 13:57
 *****/
public class VolatileAtomicSample {

    private static int counter = 0;

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            Thread thread = new Thread(new Runnable() {
                public void run() {
                    synchronized (VolatileAtomicSample.class) {
                        for (int j = 0; j < 1000; j++) {
                            counter++;
                        }
                    }
                }
            });
            thread.start();
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(counter);
    }
}
